package com.ruoyi.delivery.service.impl;

import com.ruoyi.delivery.domain.DelVehicle;
import com.ruoyi.delivery.domain.dto.Monitor;
import com.ruoyi.delivery.mapper.DelVehicleMapper;
import com.ruoyi.delivery.service.IDelVehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DelVehicleServiceImpl implements IDelVehicleService {

    @Autowired
    private DelVehicleMapper delVehicleMapper;

    /**
     * 获取车辆信息列表，支持分页和筛选
     *
     * @param vehicleNo     车辆编号
     * @param vehiclePerson 车辆负责人
     * @param vehicleType   车辆类型
     * @param capacity      容量
     * @param startDate     创建时间开始范围
     * @param endDate       创建时间结束范围
     * @param activeStatus  生效状态
     * @param page          页码
     * @param pageSize      每页记录数
     * @return 车辆信息列表
     */
    @Override
    public List<DelVehicle> getVehicleList(String vehicleNo, String vehiclePerson, String vehicleType, Double capacity,
                                           String startDate, String endDate, Boolean activeStatus,
                                           int page, int pageSize, String logisticsDeliver) {
        int offset = (page - 1) * pageSize;
        return delVehicleMapper.getVehicleList(vehicleNo, vehiclePerson, vehicleType, capacity,
                startDate, endDate, activeStatus, offset, pageSize, logisticsDeliver);
    }

    /**
     * 获取车辆信息总记录数
     *
     * @param vehicleNo     车辆编号
     * @param vehiclePerson 车辆负责人
     * @param vehicleType   车辆类型
     * @param capacity      容量
     * @param startDate     创建时间开始范围
     * @param endDate       创建时间结束范围
     * @param activeStatus  生效状态
     * @return 总记录数
     */
    @Override
    public int getVehicleCount(String vehicleNo, String vehiclePerson, String vehicleType, Double capacity,
                               String startDate, String endDate, Boolean activeStatus, String logisticsDeliver) {
        return delVehicleMapper.getVehicleCount(vehicleNo, vehiclePerson, vehicleType, capacity,
                startDate, endDate, activeStatus, logisticsDeliver);
    }

    /**
     * 新建车辆信息
     *
     * @param vehicle 车辆信息对象
     */
    @Override
    public void insertVehicleInfo(DelVehicle vehicle) {
        int result = delVehicleMapper.insertVehicleInfo(vehicle);
        if (result != 1) {
            throw new RuntimeException("插入车辆信息失败");
        }
    }

    /**
     * 更新车辆信息
     *
     * @param vehicle 车辆信息对象
     */
    @Override
    public void updateVehicleInfo(DelVehicle vehicle) {
        int result = delVehicleMapper.updateVehicleInfo(vehicle);
        if (result != 1) {
            throw new RuntimeException("更新车辆信息失败");
        }
    }

    /**
     * 删除车辆信息
     *
     * @param vehicleNo 车辆编号
     */
    @Override
    public void deleteVehicle(String vehicleNo) {
        int result = delVehicleMapper.deleteVehicle(vehicleNo);
        if (result != 1) {
            throw new RuntimeException("删除车辆信息失败");
        }
    }

    /**
     * 批量删除车辆信息
     *
     * @param vehicleNos 车辆编号列表
     */
    @Override
    public void deleteVehicles(List<String> vehicleNos) {
        int result = delVehicleMapper.deleteVehicles(vehicleNos);
        if (result != vehicleNos.size()) {
            throw new RuntimeException("批量删除车辆信息失败");
        }
    }

    /**
     * 获取车辆位置信息
     *
     * @param logisticsDeliver 物流商编号
     * @return 车辆位置信息
     */
    @Override
    public List<Monitor> getVehicleLocation(String logisticsDeliver) {
        return delVehicleMapper.getVehicleLocation(logisticsDeliver);
    }

    /**
     * 获取车辆信息
     *
     * @param logisticsDeliver 物流商编号
     * @return 车辆信息
     */
    @Override
    public List<DelVehicle> getVehicleInfo(String logisticsDeliver) {
        return delVehicleMapper.getAllVehicle(logisticsDeliver);
    }


}
